package com.ruoyi.web.controller.marry;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.marry.domain.TGiftInfo;
import com.ruoyi.marry.service.ITGiftInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 礼物管理Controller
 *
 * @author user_marry
 * @date 2020-11-25
 */
@RestController
@RequestMapping("/marry/giftInfo")
public class TGiftInfoController extends BaseController {

    @Autowired
    private ITGiftInfoService tGiftInfoService;

    /**
     * 查询礼物管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:giftInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TGiftInfo tGiftInfo) {
        startPage();
        List<TGiftInfo> list = tGiftInfoService.selectTGiftInfoList(tGiftInfo);
        return getDataTable(list);
    }

    /**
     * 导出礼物管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:giftInfo:export')")
    @Log(title = "礼物管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TGiftInfo tGiftInfo) {
        List<TGiftInfo> list = tGiftInfoService.selectTGiftInfoList(tGiftInfo);
        ExcelUtil<TGiftInfo> util = new ExcelUtil<TGiftInfo>(TGiftInfo.class);
        return util.exportExcel(list, "giftInfo");
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('marry:giftInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(tGiftInfoService.selectTGiftInfoById(id));
    }

    /**
     * 新增保存礼物管理
     */
    @PreAuthorize("@ss.hasPermi('marry:giftInfo:add')")
    @Log(title = "礼物管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TGiftInfo tGiftInfo) {
        return toAjax(tGiftInfoService.insertTGiftInfo(tGiftInfo));
    }

    /**
     * 修改保存礼物管理
     */
    @PreAuthorize("@ss.hasPermi('marry:giftInfo:edit')")
    @Log(title = "礼物管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TGiftInfo tGiftInfo) {
        return toAjax(tGiftInfoService.updateTGiftInfo(tGiftInfo));
    }

    /**
     * 删除礼物管理
     */
    @PreAuthorize("@ss.hasPermi('marry:giftInfo:remove')")
    @Log(title = "礼物管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tGiftInfoService.deleteTGiftInfoByIds(ids));
    }
}
